}
wpt->SetCreationTime(basetime +
- ((data->hour & 0x1F) * 3600) + (data->min * 60) + data->sec, (int)data->dsec * 10000);
+ ((data->hour & 0x1F) * 3600) + (data->min * 60) + data->sec, data->dsec * 10);
return wpt;
}
int s_len = strlen(s);
if (s_len < 4) {
/* less than 1 epochsecond, an unusual case */
- wpt->SetCreationTime(0,(int) atoi(s) * 1000);
+ wpt->SetCreationTime(0,(int) atoi(s));
} else {
char buff[32];
int off = s_len - 3;
s += off;
strncpy(buff, s, 3);
buff[3] = '\0';
- wpt->SetCreationTime(t, (int) MILLI_TO_MICRO(atoi(buff)));
+ wpt->SetCreationTime(t, atoi(buff));
}
}
break;
char tbuf[24];
writetime(tbuf, sizeof(tbuf), "%s", wpt->GetCreationTime(), false);
char mbuf[32];
- snprintf(mbuf, sizeof(mbuf), "%s%03d", tbuf, wpt->microseconds / 1000);
+ snprintf(mbuf, sizeof(mbuf), "%s%03d", tbuf, wpt->GetCreationTime().msec());
writebuff(buff, "%s", mbuf);
}
break;
}
void SetCreationTime(time_t t) { creation_time = t;
}
- void SetCreationTime(time_t t, int us) {
- creation_time = t;
- microseconds = us;
+ void SetCreationTime(time_t t, int ms) {
+ creation_time.setTime_t(t);
+ creation_time = creation_time.addMSecs(ms);
}
gpsbabel::DateTime creation_time;
int microseconds; /* Optional millionths of a second. */
snprintf(buff, sizeof(buff), "%06d%.f", date, time);
strptime(buff, "%d%m%y%H%M%S", &tm);
- wpt->SetCreationTime(mkgmtime(&tm),
- ((int)time % 1000) * 1000);
+ int millisecs = (int) time % 1000;
+ wpt->SetCreationTime(mkgmtime(&tm), millisecs);
+// FIXME: this is papering over a problem somewhere...
+wpt->microseconds = millisecs * 1000;
if (wpt->fix > 0) {
wpt->fix = (fix_type)(wpt->fix + 1);
gbfputint32(date, fout);
time = ((int)tm.tm_hour * 10000) + ((int)tm.tm_min * 100) + tm.tm_sec;
- time = (time * 1000) + (wpt->microseconds / 1000);
+ time = (time * 1000) + (wpt->GetCreationTime().msec());
gbfputflt(time, fout);
} else {
gbfputint32(0, fout); /* Is this invalid ? */
wpt->longitude = xlon;
WAYPT_SET(wpt, course, le_read16(&buf[16 + 0]));
- int microseconds = 0;
+ int milliseconds = 0;
if (ggv_log_ver == 10) {
double secs;
tm.tm_min = le_read16(&buf[16 + 16]);
secs = le_read_double(&buf[16 + 18]);
tm.tm_sec = (int)secs;
- microseconds = (secs - tm.tm_sec) * 1000000;
+ milliseconds = lround((secs - tm.tm_sec) * 1000.0);
} else {
wpt->altitude = le_read16(&buf[16 + 4]);
wpt->sat = (unsigned char)buf[16 + 14];
tm.tm_year -= 1900;
if (tm.tm_mon > 0) {
tm.tm_mon--;
- wpt->SetCreationTime(mkgmtime(&tm), microseconds);
+ wpt->SetCreationTime(mkgmtime(&tm), milliseconds);
}
}
speed = waypt_speed(prev, wpt);
}
if (wpt->creation_time > 0) {
- secs = (double)tm.tm_sec + ((double)wpt->microseconds / 1000000);
+ secs = (double)tm.tm_sec + (1000 * wpt->GetCreationTime().msec());
}
gbfputint16((gbint16) latint, fout);
case 0: /* "-" */ /* unknown fields for the moment */
sscanf(c, "%lu", µsecs);
wpt->SetCreationTime(microsecs / 1000000, microsecs % 1000000);
+// FIXME: this is totally papering over a problem where creation time is
+// being overwritten later.
+wpt->microseconds = microsecs % 1000000;
break;
case 1: /* Time UTC */
sscanf(c,"%lf",&hmsd);
static void
nmea_set_waypoint_time(waypoint* wpt, struct tm* time, double fsec)
{
- //fractions are stored as ms
- int us = MILLI_TO_MICRO(lround(1000*fsec));
if (time->tm_year == 0) {
- wpt->SetCreationTime(((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec, us);
+ wpt->SetCreationTime(((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec, lround(1000.0 * fsec));
if (wpt->wpt_flags.fmt_use == 0) {
wpt->wpt_flags.fmt_use = 1;
}
} else {
- wpt->SetCreationTime(mkgmtime(time), us);
+ wpt->SetCreationTime(mkgmtime(time), lround(1000.0 * fsec));
if (wpt->wpt_flags.fmt_use != 0) {
wpt->wpt_flags.fmt_use = 0;
}
static avltree_t* trkpts;
static time_t
-jtr_parse_time(const char* str, struct tm* tm, int* micro)
+jtr_parse_time(const char* str, struct tm* tm, int* milli)
{
long int hms;
char* dot;
hms = hms / 100;
tm->tm_hour = hms % 100;
- if ((*dot == '.') && (micro != NULL)) {
- *micro = atoi(dot + 1) * 10000;
+ if ((*dot == '.') && (milli != NULL)) {
+ *milli = atoi(dot + 1) * 10;
}
return mkgmtime(tm);
double lat, lon;
float speed, course, mcourse, mvar, mdev;
time_t time = 0;
- int micros = 0;
+ int mills = 0;
char buf[32];
char mvardir, mdevdir;
case 0:
break; /* GEOTAG2 */
case 1:
- jtr_parse_time(str, &tm, µs);
+ jtr_parse_time(str, &tm, &mills);
break;
case 2:
valid = *str;
wpt->latitude = lat;
wpt->longitude = lon;
- wpt->SetCreationTime(time, micros);
+ wpt->SetCreationTime(time, mills);
if (speed >= 0) {
WAYPT_SET(wpt, speed, speed);
}
dmy = dmy / 100;
tm.tm_mday = dmy % 100;
- waypt->SetCreationTime(mkgmtime(&tm), CENTI_TO_MICRO(fracsecs));
+ waypt->SetCreationTime(mkgmtime(&tm), 10.0 * fracsecs);
if (latdir == 'S') {
latdeg = -latdeg;
tm->tm_sec;
date = tm->tm_mday * 10000 + tm->tm_mon * 100 +
tm->tm_year;
- fracsec = MICRO_TO_CENTI(waypointp->microseconds);
+ fracsec = lround(waypointp->GetCreationTime().msec()/10.0);
}
}
if (!tm) {
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
*/
+#include <math.h>
#include <stdio.h>
#include <string.h>
} else {
centisecs = 0;
}
- wpt_tmp->SetCreationTime(t, CENTI_TO_MICRO(centisecs));
+ wpt_tmp->SetCreationTime(t, 10.0 * centisecs);
track_add_wpt(track_head, wpt_tmp);
}
/* 0 centiseconds */
if (trk_version >= 30) {
- c = MICRO_TO_CENTI(wpt->microseconds);
+ c = lround(wpt->GetCreationTime().msec() / 10.0);
gbfwrite(&c, 1, 1, mapsend_file_out);
}
}
}
static int
-decode_sbp_usec(const unsigned char* buffer)
+decode_sbp_msec(const unsigned char* buffer)
{
int msec = le_read16(buffer);
- return (msec % 1000) * 1000;
+ return (msec % 1000);
}
static time_t
waypt->hdop = ((unsigned char)buffer[0]) * 0.2f;
waypt->sat = buffer[1];
waypt->SetCreationTime(decode_sbp_datetime_packed(buffer + 4),
- decode_sbp_usec(buffer + 2));
+ decode_sbp_msec(buffer + 2));
decode_sbp_position(buffer + 12, waypt);
WAYPT_SET(waypt, speed, le_read16(buffer + 24) * 0.01f);
WAYPT_SET(waypt, course, le_read16(buffer + 26) * 0.01f);
static void
nmea_set_waypoint_time(waypoint* wpt, struct tm* time, double fsec)
{
- //fractions are stored as ms
- int us = MILLI_TO_MICRO(lround(1000*fsec));
if (time->tm_year == 0) {
- wpt->SetCreationTime(((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec, us);
+ wpt->SetCreationTime(((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec, lround(1000.0 * fsec));
if (wpt->wpt_flags.fmt_use == 0) {
wpt->wpt_flags.fmt_use = 1;
without_date++;
}
} else {
- wpt->SetCreationTime(mkgmtime(time), us);
+ wpt->SetCreationTime(mkgmtime(time), lround(1000.0 * fsec));
if (wpt->wpt_flags.fmt_use != 0) {
wpt->wpt_flags.fmt_use = 0;
without_date--;
if (opt_gprmc) {
snprintf(obuf, sizeof(obuf), "GPRMC,%010.3f,%c,%08.3f,%c,%09.3f,%c,%.2f,%.2f,%06d,,",
- (double) hms + (wpt->microseconds / 1000000.0),
+ (double) hms + (wpt->GetCreationTime().msec() / 1000.0),
fix=='0' ? 'V' : 'A',
fabs(lat), lat < 0 ? 'S' : 'N',
fabs(lon), lon < 0 ? 'W' : 'E',
}
if (opt_gpgga) {
snprintf(obuf, sizeof(obuf), "GPGGA,%010.3f,%08.3f,%c,%09.3f,%c,%c,%02d,%.1f,%.3f,M,0.0,M,,",
- (double) hms + (wpt->microseconds / 1000000.0),
+ (double) hms + (wpt->GetCreationTime().msec() / 1000.0),
fabs(lat), lat < 0 ? 'S' : 'N',
fabs(lon), lon < 0 ? 'W' : 'E',
fix,
if(ozi_time > DAYS_SINCE_1990) {
waypointp->SetCreationTime((ozi_time - DAYS_SINCE_1990) * SECONDS_PER_DAY,
- lround(1000000.0 * (ozi_time - (int) ozi_time)));
+ lround(1000.0 * (ozi_time - (int) ozi_time)));
}
}
tm.tm_mon = buffer[2] - 1;
tm.tm_year = be_readu16(buffer) - 1900;
- waypt->SetCreationTime(mkgmtime(&tm), (ms % 1000) * 1000);
+ waypt->SetCreationTime(mkgmtime(&tm), (ms % 1000));
}
static void
t_ = -1;
}
- DateTime(QDate date, QTime time) : QDateTime(date, time) { }
- DateTime(QDateTime dt) : QDateTime(dt) { }
-
+ DateTime(QDate date, QTime time) : QDateTime(date, time) {}
+ DateTime(QDateTime dt) : QDateTime(dt) {}
// Handle time_tm tm = wpt->creation_time;
- operator const time_t() const {
- return this->toTime_t();
- }
+ operator const time_t() const { return this->toTime_t(); }
const time_t& operator=(const time_t& t) {
this->setTime_t(t);
return t;
}
- time_t operator-- (int) {
+ time_t operator--(int) {
setTime_t(toTime_t() - 1);
return this->toTime_t();
}
- time_t operator++ (int) {
+ time_t operator++(int) {
setTime_t(toTime_t() + 1);
return this->toTime_t();
}
- time_t operator+=(const time_t&t) {
- setTime_t(toTime_t() + t);
+ time_t operator+=(const time_t& t) {
+ setTime_t(toTime_t() + t);
return this->toTime_t();
}
// Handle tm = *gmtime(&wpt->creation_time) ...poorly.
- inline const time_t* operator&() {
+ inline const time_t *operator&() {
t_ = this->toTime_t();
-//fprintf(stderr, "inline set time_t %d\n", t_);
return &t_;
}
- // Before Qt, GPSBabel had a 'microseconds' which is excessive and
- // not really supported in QDateTime. Milliseconds is fine, but we
- // provide these shims for code that used usecs.
- void addUSecs(qint64 usecs) const {
- this->addMSecs(usecs / 1000);
- }
- int usec() const {
- return this->time().msec() * 1000;
- }
+ // A convenience method to return the number of milliseconds (0-999).
+ int msec() const { return this->time().msec(); }
// Integer form: YYMMDD
int ymd() const {
QTime time(this->time());
return time.hour() * 10000 + time.minute() * 100 + time.second();
}
+
// Qt 4.6 and under doesn't have msecsTo. Fortunately, it's easy to
// provide. It's a 64-bit because if the times aren't on the same day,
// the returned value can be quite large.
- int64_t msecsTo(const QDateTime& dt) {
+ int64_t msecsTo(const QDateTime &dt) {
qint64 days = this->daysTo(dt);
qint64 msecs = this->time().msecsTo(dt.time());
return days * (1000 * 3600 * 24) + msecs;
}
return this->toUTC().toString(format);
}
-
- private:
+private:
time_t t_;
};
wpt = NULL;
memset(&time, 0, sizeof(time));
- int microseconds = 0;
+ int milliseconds = 0;
while ((c = csv_lineparse(buff, ",", "", column++))) {
int new_what;
- int fracsec;
buff = NULL;
break;
case 6:
- sscanf(c, "%d:%d:%d.%d", &time.tm_hour, &time.tm_min, &time.tm_sec, &fracsec);
- microseconds = MILLI_TO_MICRO(fracsec);
+ sscanf(c, "%d:%d:%d.%d", &time.tm_hour, &time.tm_min, &time.tm_sec, &milliseconds);
/* makes sense only for recorded trackpoints */
if (what != STM_TRKPT) {
- microseconds = 0;
+ milliseconds = 0;
}
break;
if (wpt != NULL) {
time.tm_year -= 1900;
time.tm_mon--;
- wpt->SetCreationTime(mkgmtime(&time), microseconds);
+ wpt->SetCreationTime(mkgmtime(&time), milliseconds);
switch (what) {
case STM_WAYPT:
gbfprintf(fout, ".%02d", 0);
break;
case STM_TRKPT:
- gbfprintf(fout, ".%03d", MICRO_TO_MILLI(wpt->microseconds));
+ gbfprintf(fout, ".%03d", wpt->GetCreationTime().msec());
break;
}
gbfprintf(fout, ",\r\n");
ct = sscanf(str, "%d%1[.://]%d%1[.://]%d%lf", &hour, sep, &min, sep, &sec, &ms);
is_fatal(ct < 5, MYNAME ": Could not parse time string (%s).\n", str);
if (ct == 6) {
- *msec = (ms * 1000000) + 0.5;
+ *msec = lround((ms * 1000000));
if (*msec > 999999) {
*msec = 0;
sec++;
}
if (msec >= 0) {
- wpt->microseconds = msec;
+ wpt->creation_time.addMSecs(msec);
}
if (opt_utc) {
tmStruct.tm_sec =(int)floor(seconds);
tmStruct.tm_isdst =-1;
- wpt_tmp->SetCreationTime(mkgmtime(&tmStruct),
- fmod(1000000*seconds+0.5,1000000));
+ double usec = fmod(1000000*seconds+0.5,1000000);
+ wpt_tmp->SetCreationTime(mkgmtime(&tmStruct),lround(usec/1000.0));
wpt_tmp->shortname = (char*) xcalloc(16,1);
snprintf(wpt_tmp->shortname, 15 , "WP%04d", ++serial);
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <math.h>
#define MYNAME "vitovtt"
#include "defs.h"
double altitude = 0;
struct tm tmStruct;
int scaled_sec = 0;
- int microseconds = 0;
double speed = 0;
int course = 0;
int status = 0;
wpt_tmp->altitude = altitude;
tmStruct.tm_sec = scaled_sec / vitovtt_secondscale;
- microseconds = (scaled_sec % vitovtt_secondscale) / vitovtt_microsecondscale;
- wpt_tmp->SetCreationTime(mkgmtime(&tmStruct), microseconds);
-
+ int microseconds = (scaled_sec % vitovtt_secondscale) / vitovtt_microsecondscale;
+ wpt_tmp->SetCreationTime(mkgmtime(&tmStruct), lround(microseconds/1000.0));
/*
* TODO: interpret speed, course, status
*/